package com.what21.netfwd;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
 
public class ForwardThread extends Thread {
 
    private static final int BUFFER_SIZE = 8192;
 
    private InputStream input;
    private OutputStream output;
    ClientThread parent;
 
      
    public ForwardThread(ClientThread parent, InputStream input, OutputStream output) {
        this.parent = parent;
        this.input = input;
        this.output = output;
    }
      
    public void run() {
        try {
            byte[] buffer = new byte[BUFFER_SIZE];
            while (true) {
                int bytesRead = this.input.read(buffer);
                if (bytesRead == -1){
                    break; 
                }
                this.output.write(buffer, 0, bytesRead);
                this.output.flush();
            }
        } catch (IOException e) {
              
        }
        this.parent.close();
    }
 
}